package com.jming.yygh.hosp.controller;

import com.jming.yygh.common.result.Result;
import com.jming.yygh.hosp.service.HospitalService;
import com.jming.yygh.hosp.service.ScheduleService;
import com.jming.yygh.model.hosp.Hospital;
import com.jming.yygh.vo.hosp.HospitalQueryVo;
import com.jming.yygh.vo.hosp.ScheduleOrderVo;
import com.jming.yygh.vo.hosp.ScheduleQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @author jming
 * @date 2021-04-23
 */

@Api(tags = "医院管理接口")
//@CrossOrigin  // 允许跨域访问
@RestController   // Rest风格注入
@RequestMapping("/admin/hosp/hospital")
public class HospitalController {

    @Resource
    private HospitalService hospitalService;

    @Resource
    private ScheduleService scheduleService;

    /**
     * 条件查询医院列表带分页
     *
     * @param page               当前页
     * @param limit              每页记录数
     * @param hospitalQueryVo 查询条件
     * @return 查询结果
     */
    @ApiOperation(value = "条件查询医院列表带分页")
    @GetMapping("list/{page}/{limit}")
    public Result<Page<Hospital>> listHosp(@PathVariable Integer page,
                                           @PathVariable Integer limit,
                                           HospitalQueryVo hospitalQueryVo) {

        Page<Hospital> pageModel = hospitalService.selectHospPage(page, limit, hospitalQueryVo);

        return Result.ok(pageModel);
    }


    /**
     * 根据id跟新医院状态
     * @param id id
     * @param status 状态
     * @return 更新结果
     */
    @ApiOperation(value = "根据id跟新医院状态")
    @PutMapping("updateHospStatus/{id}/{status}")
    public Result updateHospStatus(@PathVariable String id,
                                   @PathVariable Integer status) {

        hospitalService.updateStatus(id, status);
        return Result.ok();
    }


    /**
     * 根据id查询医院详细信息
     * @param id 医院id
     * @Author jming
     * @Date 2021/5/5
     * @return Result 查询结果
     */
    @ApiOperation(value = "根据id查询医院详细信息")
    @GetMapping("showHospDetail/{id}")
    public Result showHospDetail(@PathVariable String id) {

       Map<String, Object> map = hospitalService.getHospById(id);

        return Result.ok(map);
    }

    /**
     * 根据排班id获取预约下单数据
     * @param scheduleId
     * @return ScheduleQueryVo
     */
    @ApiOperation(value = "根据排班id获取预约下单数据")
    @GetMapping("inner/getscheduleOrderVo/{scheduleId}")
    public ScheduleOrderVo getscheduleOrderVo(@PathVariable String scheduleId) {

        return scheduleService.scheduleOrderVo(scheduleId);
    }

}
